package com.thssh.ui.lsn03.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.SwitchCompat;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.EditText;

import com.thssh.ui.R;
import com.thssh.ui.lsn03.view.PaintHelpView;

public class PaintHelpActivity extends AppCompatActivity {

    private PaintHelpView paint_help_view;
    private SwitchCompat swh_anti_alias;
    private SwitchCompat swh_random_path;
    private EditText et_paint_width;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_paint_help);
        paint_help_view = (PaintHelpView) findViewById(R.id.paint_help_view);
        swh_anti_alias = (SwitchCompat) findViewById(R.id.swh_anti_alias);
        swh_random_path = (SwitchCompat) findViewById(R.id.swh_random_path);
        et_paint_width = (EditText) findViewById(R.id.et_paint_width);

        initEvents();
        initViewData();
    }

    private void initViewData() {
        resetPaintWidthEditTextHint();
    }

    private void resetPaintWidthEditTextHint() {
        int paintWidth = paint_help_view.getPaintWidth();
        et_paint_width.setHint("当前画笔宽度：" + paintWidth);
    }

    private void initEvents() {
        swh_anti_alias.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                paint_help_view.setPaintAntiAlias(b);
            }
        });
        swh_random_path.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                paint_help_view.setRandomPath(b);
            }
        });
    }

    public void setPaintWidthClick(View view) {
        String widthStr = et_paint_width.getText().toString().trim();
        int width = 80;
        try{
            width = Integer.parseInt(widthStr);
        }catch (Exception e){}
        paint_help_view.setPaintWidth(width);
        et_paint_width.setText("");
        resetPaintWidthEditTextHint();
    }

    public void buttStrokeCapClick(View view) {
        paint_help_view.setStrokeCapType(0);
    }

    public void roundStrokeCapClick(View view) {
        paint_help_view.setStrokeCapType(1);
    }

    public void squareStrokeCapClick(View view) {
        paint_help_view.setStrokeCapType(2);
    }

    public void joinBevelClick(View view) {
        paint_help_view.setStrokeJoinType(0);
    }

    public void joinRoundClick(View view) {
        paint_help_view.setStrokeJoinType(1);
    }

    public void joinMiterClick(View view) {
        paint_help_view.setStrokeJoinType(2);
    }

    public void fillStyleClick(View view) {
        paint_help_view.setPaintStyle(0);
    }

    public void fillAndStrokeStyleClick(View view) {
        paint_help_view.setPaintStyle(1);
    }

    public void strokeStyleClick(View view) {
        paint_help_view.setPaintStyle(2);
    }

    public void dashPathEffectClick(View view) {
        paint_help_view.setPaintPathEffectType(0);
    }

    public void discretePathEffectClick(View view) {
        paint_help_view.setPaintPathEffectType(1);
    }

    public void cornerEffectClick(View view) {
        paint_help_view.setPaintPathEffectType(2);
    }

    public void composePathEffectClick(View view) {
        paint_help_view.setPaintPathEffectType(3);
    }
}
